﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Xml;

namespace BLL
{
    public class TempleteBLL
    {
        private static string ConfigPath
        {
            get
            {
                return Comm.Config.BaseDirectory + "ExportFile\\Templete\\Project.xml";
            }
        }

        public static List<Templete> GetTemplete(string sheetName)
        {
            List<Templete> lst = new List<Templete>();
            XmlDocument doc = new XmlDocument();
            doc.Load(ConfigPath);
            var root = doc.DocumentElement;
            var nodes = root.SelectNodes("datas");
            foreach (XmlNode node in nodes)
            {
                string con = node.Attributes["sheetName"] == null ? "" : node.Attributes["sheetName"].Value;
                if (con == sheetName)
                {
                    var nodes2 = node.SelectNodes("data");
                    foreach (XmlNode node2 in nodes2)
                    {
                        Templete data = new Templete();
                        var temp1 = node2.Attributes["columnName"];
                        if (temp1 != null)
                        {
                            data.columnName = temp1.Value;
                        }
                        var temp2 = node2.Attributes["dataName"];
                        if (temp2 != null)
                        {
                            data.dataName = temp2.Value;
                        }
                        var temp3 = node2.Attributes["formatStr"];
                        if (temp3 != null)
                        {
                            data.formatStr = temp3.Value;
                        }
                        var temp4 = node2.Attributes["columnWidth"];
                        if (temp4 != null)
                        {
                            data.columnWidth = Convert.ToInt32(temp4.Value);
                        }

                        data.sheetName = con;
                        lst.Add(data);
                    }
                    break;
                }
            }
            return lst;
        }
    }
}
